import { findAllCategory } from '@/api/category'
import { topCategory } from '@/api/constants'
export default {
  namespaced: true,
  state: {
    list: topCategory.map(item => {
      return { name: item }
    })
  },
  mutations: {
    setList (state, list) {
      state.list = list
    },
    show (state, id) {
      const obj = state.list.find(item => item.id === id)
      obj.open = true
    },
    hide (state, id) {
      const obj = state.list.find(item => item.id === id)
      obj.open = false
    }
  },
  actions: {
    async  getList ({ commit }) {
      const res = await findAllCategory()
      res.result.map(item => { item.open = false })

      commit('setList', res.result)
    }

  }
}
